package sea;

import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ListModel;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import sea.plot.PlotForm;
import sea.simulate.SimulateForm;
import sea.simulate.SimulateSaveForm;
import sea.util.FileHelper;
import sea.util.ModelFile;
import sea.util.PublicParam;
import sea.util.SimHyAHelper;
import sea.util.TxtFilter;
import sea.util.WinHelper;
import simhya.gui.TextAreaStream;
import simhya.script.CommandManager;

/**
 *
 * This class builds the layout of main interface
 * 
 * @author  Zhirun Ding
 * 
 * Created on 11/07/2012
 * 
 */

public class SimHyAMainFrame extends javax.swing.JFrame {
    
    /** Creates new form NewJFrame */
    public SimHyAMainFrame() {
        initComponents();
        
        //get the software title
         softTitle = this.getTitle();
        
        //init working directory
        String path = PublicParam.SimHyACommand.getWorkingDirectory().getAbsolutePath();
        PublicParam.WorkingDirectory = PublicParam.SimHyACommand.getWorkingDirectory().getAbsolutePath();
        //System.out.println(path);
        readModelNameToList(path);
        this.currentDirField.setText(PublicParam.WorkingDirectory);
        
        //init out the object
        //PublicParam.SimHyACommand.setJTextAreaOutput(consoleMessageTextArea, errorTextArea);  
        PublicParam.SimHyACommand.setOutputStream(new TextAreaStream(consoleMessageTextArea));
        PublicParam.SimHyACommand.setErrorStream(new TextAreaStream(errorTextArea));   
        //((CommandManager)PublicParam.SimHyACommand).setEmbeddedInGuiStatus(false);
        //((CommandManager)PublicParam.SimHyACommand).setPanelOutput(plotPanel);        
        
        //hide button
        //addButton.setVisible(false);
        //loadButton.setVisible(false);
        
        //modelNameLabel.setVisible(false);
       
        
        //store this mainform to public param
        PublicParam.SimHyAMainFrame = this;
        
        //set the window maximized
        this.setDefaultLookAndFeelDecorated(true);
        GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
        this.setMaximizedBounds(env.getMaximumWindowBounds());
        this.setExtendedState(this.getExtendedState() | this.MAXIMIZED_BOTH);
        //this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        this.setLocationRelativeTo(null);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The contents of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        closetabPopupMenu = new javax.swing.JPopupMenu();
        closeMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        closealltabsMenuItem = new javax.swing.JMenuItem();
        closeothertabsMenuItem = new javax.swing.JMenuItem();
        jSeparator8 = new javax.swing.JSeparator();
        detachfromtabMenuItem = new javax.swing.JMenuItem();
        clearPopupMenu = new javax.swing.JPopupMenu();
        clearMenuItem = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        saveasMenuItem = new javax.swing.JMenuItem();
        navigatorPopupMenu = new javax.swing.JPopupMenu();
        openNavigatorMenuItem = new javax.swing.JMenuItem();
        parseNavigatorMenuItem = new javax.swing.JMenuItem();
        jSeparator10 = new javax.swing.JSeparator();
        deleteNavigatorMenuItem = new javax.swing.JMenuItem();
        commandText = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        currentDirField = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        navigatorList = new javax.swing.JList();
        modelTabbedPane = new javax.swing.JTabbedPane();
        infoTabPanel = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextArea3 = new javax.swing.JTextArea();
        jScrollPane6 = new javax.swing.JScrollPane();
        consoleMessageTextArea = new javax.swing.JTextArea();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        errorTextArea = new javax.swing.JTextArea();
        simulateButton = new javax.swing.JButton();
        exploreButton = new javax.swing.JButton();
        plotButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        loadButton = new javax.swing.JButton();
        browseButton = new javax.swing.JButton();
        refreshButton = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu simHyAMenu = new javax.swing.JMenu();
        simulateMenuItem = new javax.swing.JMenuItem();
        exploreMenuItem = new javax.swing.JMenuItem();
        plotMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        jSeparator6 = new javax.swing.JPopupMenu.Separator();
        exitMenuItem = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        parseMenuItem = new javax.swing.JMenuItem();
        jSeparator7 = new javax.swing.JSeparator();
        newMenuItem = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JSeparator();
        saveModelMenuItem = new javax.swing.JMenuItem();
        saveasModelMenuItem = new javax.swing.JMenuItem();
        jSeparator13 = new javax.swing.JPopupMenu.Separator();
        exportMenuItem = new javax.swing.JMenuItem();
        jSeparator5 = new javax.swing.JSeparator();
        deleteModelMenuItem = new javax.swing.JMenuItem();
        jSeparator12 = new javax.swing.JSeparator();
        closethistabMenuItem = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        showorhideMenuItem = new javax.swing.JMenuItem();
        jSeparator11 = new javax.swing.JSeparator();
        helpMenuItem = new javax.swing.JMenuItem();
        jSeparator9 = new javax.swing.JSeparator();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();

        closetabPopupMenu.setName("closetabPopupMenu"); // NOI18N
        closetabPopupMenu.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
                closetabPopupMenuPopupMenuWillBecomeVisible(evt);
            }
        });

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(SimHyAMainFrame.class);
        closeMenuItem.setText(resourceMap.getString("closeMenuItem.text")); // NOI18N
        closeMenuItem.setToolTipText(resourceMap.getString("closeMenuItem.toolTipText")); // NOI18N
        closeMenuItem.setName("closeMenuItem"); // NOI18N
        closeMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeMenuItemActionPerformed(evt);
            }
        });
        closetabPopupMenu.add(closeMenuItem);

        jSeparator1.setName("jSeparator1"); // NOI18N
        closetabPopupMenu.add(jSeparator1);

        closealltabsMenuItem.setText(resourceMap.getString("closealltabsMenuItem.text")); // NOI18N
        closealltabsMenuItem.setToolTipText(resourceMap.getString("closealltabsMenuItem.toolTipText")); // NOI18N
        closealltabsMenuItem.setName("closealltabsMenuItem"); // NOI18N
        closealltabsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closealltabsMenuItemActionPerformed(evt);
            }
        });
        closetabPopupMenu.add(closealltabsMenuItem);

        closeothertabsMenuItem.setText(resourceMap.getString("closeothertabsMenuItem.text")); // NOI18N
        closeothertabsMenuItem.setToolTipText(resourceMap.getString("closeothertabsMenuItem.toolTipText")); // NOI18N
        closeothertabsMenuItem.setName("closeothertabsMenuItem"); // NOI18N
        closeothertabsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeothertabsMenuItemActionPerformed(evt);
            }
        });
        closetabPopupMenu.add(closeothertabsMenuItem);

        jSeparator8.setName("jSeparator8"); // NOI18N
        closetabPopupMenu.add(jSeparator8);

        detachfromtabMenuItem.setText(resourceMap.getString("detachfromtabMenuItem.text")); // NOI18N
        detachfromtabMenuItem.setName("detachfromtabMenuItem"); // NOI18N
        detachfromtabMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                detachfromtabMenuItemActionPerformed(evt);
            }
        });
        closetabPopupMenu.add(detachfromtabMenuItem);

        clearPopupMenu.setName("clearPopupMenu"); // NOI18N

        clearMenuItem.setText(resourceMap.getString("clearMenuItem.text")); // NOI18N
        clearMenuItem.setName("clearMenuItem"); // NOI18N
        clearMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearMenuItemActionPerformed(evt);
            }
        });
        clearPopupMenu.add(clearMenuItem);

        jSeparator2.setName("jSeparator2"); // NOI18N
        clearPopupMenu.add(jSeparator2);

        saveasMenuItem.setText(resourceMap.getString("saveasMenuItem.text")); // NOI18N
        saveasMenuItem.setName("saveasMenuItem"); // NOI18N
        saveasMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveasMenuItemActionPerformed(evt);
            }
        });
        clearPopupMenu.add(saveasMenuItem);

        navigatorPopupMenu.setName("navigatorPopupMenu"); // NOI18N

        openNavigatorMenuItem.setText(resourceMap.getString("openNavigatorMenuItem.text")); // NOI18N
        openNavigatorMenuItem.setName("openNavigatorMenuItem"); // NOI18N
        openNavigatorMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openNavigatorMenuItemActionPerformed(evt);
            }
        });
        navigatorPopupMenu.add(openNavigatorMenuItem);

        parseNavigatorMenuItem.setText(resourceMap.getString("parseNavigatorMenuItem.text")); // NOI18N
        parseNavigatorMenuItem.setName("parseNavigatorMenuItem"); // NOI18N
        parseNavigatorMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                parseNavigatorMenuItemActionPerformed(evt);
            }
        });
        navigatorPopupMenu.add(parseNavigatorMenuItem);

        jSeparator10.setName("jSeparator10"); // NOI18N
        navigatorPopupMenu.add(jSeparator10);

        deleteNavigatorMenuItem.setText(resourceMap.getString("deleteNavigatorMenuItem.text")); // NOI18N
        deleteNavigatorMenuItem.setName("deleteNavigatorMenuItem"); // NOI18N
        deleteNavigatorMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteNavigatorMenuItemActionPerformed(evt);
            }
        });
        navigatorPopupMenu.add(deleteNavigatorMenuItem);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        commandText.setName("commandText"); // NOI18N
        commandText.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                commandTextKeyReleased(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        currentDirField.setEditable(false);
        currentDirField.setText(resourceMap.getString("currentDirField.text")); // NOI18N
        currentDirField.setName("currentDirField"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        navigatorList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        navigatorList.setComponentPopupMenu(navigatorPopupMenu);
        navigatorList.setName("navigatorList"); // NOI18N
        navigatorList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                navigatorListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(navigatorList);

        modelTabbedPane.setComponentPopupMenu(closetabPopupMenu);
        modelTabbedPane.setName("modelTabbedPane"); // NOI18N
        modelTabbedPane.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                modelTabbedPaneMouseClicked(evt);
            }
        });
        modelTabbedPane.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                modelTabbedPaneStateChanged(evt);
            }
        });

        infoTabPanel.setName("infoTabPanel"); // NOI18N

        jPanel3.setName("jPanel3"); // NOI18N

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        jTextArea3.setColumns(20);
        jTextArea3.setRows(5);
        jTextArea3.setName("jTextArea3"); // NOI18N
        jScrollPane4.setViewportView(jTextArea3);

        jScrollPane6.setName("jScrollPane6"); // NOI18N

        consoleMessageTextArea.setColumns(20);
        consoleMessageTextArea.setEditable(false);
        consoleMessageTextArea.setRows(5);
        consoleMessageTextArea.setComponentPopupMenu(clearPopupMenu);
        consoleMessageTextArea.setName("consoleMessageTextArea"); // NOI18N
        consoleMessageTextArea.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                consoleMessageTextAreaCaretUpdate(evt);
            }
        });
        jScrollPane6.setViewportView(consoleMessageTextArea);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 759, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 105, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addContainerGap()))
        );

        infoTabPanel.addTab(resourceMap.getString("jPanel3.TabConstraints.tabTitle"), jPanel3); // NOI18N

        jPanel4.setName("jPanel4"); // NOI18N

        jScrollPane5.setName("jScrollPane5"); // NOI18N

        errorTextArea.setColumns(20);
        errorTextArea.setComponentPopupMenu(clearPopupMenu);
        errorTextArea.setEditable(false);
        errorTextArea.setRows(5);
        errorTextArea.setName("errorTextArea"); // NOI18N
        errorTextArea.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                errorTextAreaCaretUpdate(evt);
            }
        });
        jScrollPane5.setViewportView(errorTextArea);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 759, Short.MAX_VALUE)
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 719, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 105, Short.MAX_VALUE)
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 65, Short.MAX_VALUE)
                    .addContainerGap()))
        );

        infoTabPanel.addTab(resourceMap.getString("jPanel4.TabConstraints.tabTitle"), jPanel4); // NOI18N

        simulateButton.setText(resourceMap.getString("simulateButton.text")); // NOI18N
        simulateButton.setEnabled(false);
        simulateButton.setName("simulateButton"); // NOI18N
        simulateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                simulateButtonActionPerformed(evt);
            }
        });

        exploreButton.setText(resourceMap.getString("exploreButton.text")); // NOI18N
        exploreButton.setEnabled(false);
        exploreButton.setName("exploreButton"); // NOI18N
        exploreButton.setPreferredSize(new java.awt.Dimension(81, 23));
        exploreButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exploreButtonActionPerformed(evt);
            }
        });

        plotButton.setText(resourceMap.getString("plotButton.text")); // NOI18N
        plotButton.setEnabled(false);
        plotButton.setName("plotButton"); // NOI18N
        plotButton.setPreferredSize(new java.awt.Dimension(81, 23));
        plotButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                plotButtonActionPerformed(evt);
            }
        });

        saveButton.setText(resourceMap.getString("saveButton.text")); // NOI18N
        saveButton.setEnabled(false);
        saveButton.setName("saveButton"); // NOI18N
        saveButton.setPreferredSize(new java.awt.Dimension(81, 23));
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        loadButton.setText(resourceMap.getString("loadButton.text")); // NOI18N
        loadButton.setName("loadButton"); // NOI18N
        loadButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadButtonActionPerformed(evt);
            }
        });

        browseButton.setText(resourceMap.getString("browseButton.text")); // NOI18N
        browseButton.setName("browseButton"); // NOI18N
        browseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseButtonActionPerformed(evt);
            }
        });

        refreshButton.setText(resourceMap.getString("refreshButton.text")); // NOI18N
        refreshButton.setName("refreshButton"); // NOI18N
        refreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                refreshButtonActionPerformed(evt);
            }
        });

        menuBar.setName("menuBar"); // NOI18N

        simHyAMenu.setText(resourceMap.getString("simHyAMenu.text")); // NOI18N
        simHyAMenu.setName("simHyAMenu"); // NOI18N

        simulateMenuItem.setText(resourceMap.getString("simulateMenuItem.text")); // NOI18N
        simulateMenuItem.setEnabled(false);
        simulateMenuItem.setName("simulateMenuItem"); // NOI18N
        simulateMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                simulateMenuItemActionPerformed(evt);
            }
        });
        simHyAMenu.add(simulateMenuItem);

        exploreMenuItem.setText(resourceMap.getString("exploreMenuItem.text")); // NOI18N
        exploreMenuItem.setEnabled(false);
        exploreMenuItem.setName("exploreMenuItem"); // NOI18N
        exploreMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exploreMenuItemActionPerformed(evt);
            }
        });
        simHyAMenu.add(exploreMenuItem);

        plotMenuItem.setText(resourceMap.getString("plotMenuItem.text")); // NOI18N
        plotMenuItem.setEnabled(false);
        plotMenuItem.setName("plotMenuItem"); // NOI18N
        plotMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                plotMenuItemActionPerformed(evt);
            }
        });
        simHyAMenu.add(plotMenuItem);

        saveMenuItem.setText(resourceMap.getString("saveMenuItem.text")); // NOI18N
        saveMenuItem.setEnabled(false);
        saveMenuItem.setName("saveMenuItem"); // NOI18N
        saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuItemActionPerformed(evt);
            }
        });
        simHyAMenu.add(saveMenuItem);

        jSeparator6.setName("jSeparator6"); // NOI18N
        simHyAMenu.add(jSeparator6);

        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        simHyAMenu.add(exitMenuItem);

        menuBar.add(simHyAMenu);

        jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
        jMenu1.setName("jMenu1"); // NOI18N

        parseMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
        parseMenuItem.setText(resourceMap.getString("parseMenuItem.text")); // NOI18N
        parseMenuItem.setName("parseMenuItem"); // NOI18N
        parseMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                parseMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(parseMenuItem);

        jSeparator7.setName("jSeparator7"); // NOI18N
        jMenu1.add(jSeparator7);

        newMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        newMenuItem.setText(resourceMap.getString("newMenuItem.text")); // NOI18N
        newMenuItem.setName("newMenuItem"); // NOI18N
        newMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(newMenuItem);

        jSeparator4.setName("jSeparator4"); // NOI18N
        jMenu1.add(jSeparator4);

        saveModelMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        saveModelMenuItem.setText(resourceMap.getString("saveModelMenuItem.text")); // NOI18N
        saveModelMenuItem.setName("saveModelMenuItem"); // NOI18N
        saveModelMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveModelMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(saveModelMenuItem);

        saveasModelMenuItem.setText(resourceMap.getString("saveasModelMenuItem.text")); // NOI18N
        saveasModelMenuItem.setName("saveasModelMenuItem"); // NOI18N
        jMenu1.add(saveasModelMenuItem);

        jSeparator13.setName("jSeparator13"); // NOI18N
        jMenu1.add(jSeparator13);

        exportMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        exportMenuItem.setText(resourceMap.getString("exportMenuItem.text")); // NOI18N
        exportMenuItem.setEnabled(false);
        exportMenuItem.setName("exportMenuItem"); // NOI18N
        exportMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(exportMenuItem);

        jSeparator5.setName("jSeparator5"); // NOI18N
        jMenu1.add(jSeparator5);

        deleteModelMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.ALT_MASK));
        deleteModelMenuItem.setText(resourceMap.getString("deleteModelMenuItem.text")); // NOI18N
        deleteModelMenuItem.setName("deleteModelMenuItem"); // NOI18N
        deleteModelMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteModelMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(deleteModelMenuItem);

        jSeparator12.setName("jSeparator12"); // NOI18N
        jMenu1.add(jSeparator12);

        closethistabMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK));
        closethistabMenuItem.setText(resourceMap.getString("closethistabMenuItem.text")); // NOI18N
        closethistabMenuItem.setToolTipText(resourceMap.getString("closethistabMenuItem.toolTipText")); // NOI18N
        closethistabMenuItem.setName("closethistabMenuItem"); // NOI18N
        closethistabMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closethistabMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(closethistabMenuItem);

        jSeparator3.setName("jSeparator3"); // NOI18N
        jMenu1.add(jSeparator3);

        menuBar.add(jMenu1);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        showorhideMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.ALT_MASK));
        showorhideMenuItem.setText(resourceMap.getString("showorhideMenuItem.text")); // NOI18N
        showorhideMenuItem.setName("showorhideMenuItem"); // NOI18N
        showorhideMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showorhideMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(showorhideMenuItem);

        jSeparator11.setName("jSeparator11"); // NOI18N
        helpMenu.add(jSeparator11);

        helpMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        helpMenuItem.setText(resourceMap.getString("helpMenuItem.text")); // NOI18N
        helpMenuItem.setName("helpMenuItem"); // NOI18N
        helpMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                helpMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(helpMenuItem);

        jSeparator9.setName("jSeparator9"); // NOI18N
        helpMenu.add(jSeparator9);

        aboutMenuItem.setToolTipText(resourceMap.getString("aboutMenuItem.toolTipText")); // NOI18N
        aboutMenuItem.setLabel(resourceMap.getString("aboutMenuItem.label")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(simulateButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(exploreButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(plotButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(29, 29, 29)
                        .addComponent(loadButton, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(currentDirField, javax.swing.GroupLayout.DEFAULT_SIZE, 647, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(refreshButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(browseButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(commandText, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE)
                            .addComponent(infoTabPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE)
                            .addComponent(modelTabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 780, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(simulateButton)
                    .addComponent(exploreButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(plotButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(loadButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(currentDirField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(browseButton)
                    .addComponent(refreshButton))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(modelTabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 357, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(infoTabPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 511, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(commandText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void printMessage(String msgType, String msg) {
        if (msgType.endsWith("Info")) {
            consoleMessageTextArea.append(msg);
        } else {
            errorTextArea.append(msg);
        }
    }
    
    public int getConsoleTextLength(String msgType) {
        if (msgType.equals("Info")) {
            return consoleMessageTextArea.getText().length();
        } else {
            return errorTextArea.getText().length();
        }
    }
    
    public void showAboutBox() {
        if (aboutBox == null) {
            aboutBox = new SimHyAAboutBox(this);
            aboutBox.setLocationRelativeTo(this);
        }
        SimHyAGui.getApplication().show(aboutBox);
    }
    
    public boolean showAddModelForm() {
        //show the new model form
        if (newModelForm == null) {
            newModelForm = new NewModelForm(this, true);
            newModelForm.setLocationRelativeTo(this);
            ((NewModelForm)newModelForm).setPathToLabel(navigatorList.getToolTipText());
        }
        SimHyAGui.getApplication().show(newModelForm);
        
        if (PublicParam.NewModelFileName.length() > 0) {
            //init the model name list
            readModelNameToList(navigatorList.getToolTipText());
            //select new model name
            ListModel lm = navigatorList.getModel();
            for (int i = 0; i < lm.getSize(); i++) {
                String modelName = lm.getElementAt(i).toString();
                if (modelName.equals(PublicParam.NewModelFileName)) {
                    navigatorList.setSelectedIndex(i);   
                    //successed 
                    return true;
                }
            }
        }
        //failure 
        return false;
    }
    
    private void showFileDialog(){
        //show dialog for setting working direcotry
        JFileChooser c = new JFileChooser();
        c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        c.setDialogTitle("Select path to working directory");
        
        //set default direcotry
        if (navigatorList.getToolTipText() == null || navigatorList.getToolTipText().length() == 0) {
            // the first time read of the list
            c.setCurrentDirectory(new File(System.getProperty("user.dir")));
        } else {
            // read the list history which has be saved in tooltip
            c.setCurrentDirectory(new File(navigatorList.getToolTipText()));
        }
        
        int result = c.showOpenDialog(this);
        if (result == JFileChooser.APPROVE_OPTION) {
            //working direcotry
            String path = c.getSelectedFile().getAbsolutePath();
            //read models to list
            readModelNameToList(path);
            
        }
    }
    
    void readModelNameToList(String path) {
        //set the path to tooltip of navigatorList
        navigatorList.setToolTipText(path);
        this.setTitle(softTitle + "(" + path + ")");
        PublicParam.WorkingDirectory = path;
        this.currentDirField.setText(PublicParam.WorkingDirectory);
        //set working directory to command
        PublicParam.SimHyACommand.setWorkingDirectory(new File(path));
        
        //clear model list
        navigatorList.removeAll();

        try {
            //read all files
            DefaultListModel lm = new DefaultListModel();
            File file = new File(path);
            String[] filelist = file.list();
            for (int i = 0; i < filelist.length; i++) {
                //model file must be txt
                if (filelist[i].endsWith(".txt") | filelist[i].endsWith(".hype") | filelist[i].endsWith(".biopepa")) {
                    lm.addElement(filelist[i]);
                }
                //System.out.println(filelist[i].substring(0, filelist[i].lastIndexOf(".")));
            }
            navigatorList.setModel(lm);
        } catch (Exception e) {
        }
    }
    
    boolean checkLoadModel() {
        if (PublicParam.CurrentModelVariableName.length() == 0 ||
                SimHyAHelper.getNewDataVariableName("SIM", PublicParam.CurrentModelVariableName).length() == 0) {
            JOptionPane.showMessageDialog(this, "Please load a model file first.");
            return false;
        }
        return true;
    }
    
    public void addTab(JPanel panel) {
         //add jpanel to the tabbedpanel
         modelTabbedPane.addTab("plot_" + modelTabbedPane.getTabCount(), panel); 
         //active the new tab
         modelTabbedPane.setSelectedIndex(modelTabbedPane.getTabCount() - 1);
    }
    
    private void loadModelFile(boolean isLoad) {
        //load selected model
        if (navigatorList.getSelectedValue() == null) {
            JOptionPane.showMessageDialog(this, "Please select a model file from the list of navigator.");            
        } else {
            //get selected model name
            String modelName = navigatorList.getSelectedValue().toString();
            
            //create model file object
            ModelFile  modelFile = new ModelFile();
            modelFile.setFileName(modelName);
            modelFile.setPath(PublicParam.WorkingDirectory);
            
            //set cuurent model file(operate)
            PublicParam.CurrrentModelFileName = modelName;
            
            //modelNameLabel.setText(modelFile.getFullFilename());
            
            if (htModel.containsKey(modelFile.getFileName())) {
                //this model has opened                
                //set tab to the model
                for (int i = 0; i < modelTabbedPane.getTabCount(); i++) {
                    String title = modelTabbedPane.getTitleAt(i);
                    if (title.equals(modelFile.getFileName())) {
                        modelTabbedPane.setSelectedIndex(i);
                        break;
                    }
                }                
                //PublicParam.CurrrentModelFileName = (ModelFile)htModel.get(modelFile.getFileName());
            } else {
                //open model file
                //added a Panel and TextArea                
                JPanel panel = new JPanel();                
                                
                //add textarea to jpanel
                JTextArea textArea = new JTextArea();
                textArea.setRows(5);
                textArea.setColumns(20);                                
                JScrollPane scrollPane = new JScrollPane();                  
                scrollPane.setViewportView(textArea);                
                
                //set layout
                javax.swing.GroupLayout jPanelLayout = new javax.swing.GroupLayout(panel);
                panel.setLayout(jPanelLayout);
                jPanelLayout.setHorizontalGroup(
                    jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
                        .addContainerGap())
                );
                jPanelLayout.setVerticalGroup(
                    jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)
                        .addContainerGap())
                );
                
                //add jpanel to tabbedpanel
                modelTabbedPane.addTab(modelName, panel);  
                //JButton btnClose = new JButton("X");
                //modelTabbedPane.setTabComponentAt(modelTabbedPane.indexOfComponent(panel), btnClose);
                modelTabbedPane.validate();
                modelTabbedPane.setSelectedIndex(modelTabbedPane.getTabCount() - 1);
                modelFile.setEditTextArea(textArea);
                htModel.put(PublicParam.CurrrentModelFileName, modelFile);
                
                //read model file to textarea
                String filePath = modelFile.getFullFilename();
                String modelContent = FileHelper.readTxtFile(filePath);
                textArea.setText(modelContent);
                textArea.setCaretPosition(1);  

                //change the listener            
                textArea.getDocument().addUndoableEditListener(new UndoableEditListener(){
                    public void undoableEditHappened(UndoableEditEvent e) {                    
                        //((JTextArea)htTextArea.get(PublicParam.SelectedModelFileName)).setToolTipText("text changed");
                        String title = PublicParam.CurrrentModelFileName + "*";
                        ((ModelFile)htModel.get(PublicParam.CurrrentModelFileName)).setIsChanged(true);
                        modelTabbedPane.setTitleAt(modelTabbedPane.getSelectedIndex(), title);
                    }                
                });                
            }
            
            //load model
            if (isLoad) {
                String modelType = ((ModelFile)htModel.get(PublicParam.CurrrentModelFileName)).getModelType();        
                if (modelType.equals("other")) {
                    this.printMessage("Error", "Cannot parse current file. It is not a known model type!");
                    this.setConsoleTextAreaFocus("Error");
                } else {
                    String varName = SimHyAHelper.getNewModelVariableName(modelType, modelName); 
                    PublicParam.SimHyACommandExpression = "$" + varName + "=load(" + modelName + "," + modelType + ")";
                    PublicParam.CommandTypeName = "load";
                    int errorLength = errorTextArea.getText().length();
                    SimHyAHelper.executeCommand();

                    if (errorLength == errorTextArea.getText().length()) {
                        //if no error
                        //store model variable to PublicParam
                        PublicParam.CurrentModelVariableName = varName;
                        this.simulateButton.setEnabled(true);
                        this.exploreButton.setEnabled(true);
                        this.exportMenuItem.setEnabled(true);
                        this.simulateMenuItem.setEnabled(true);
                        this.exploreMenuItem.setEnabled(true);
                    }
                }
            }
        }
    }
    
    void setCurrentModelFile() {
        if (modelTabbedPane.getSelectedIndex() != -1) {
            //set current model file name
            String title = modelTabbedPane.getTitleAt(modelTabbedPane.getSelectedIndex());
            if (title.endsWith("*")) title = title.substring(0, title.length() - 1);
            if (title.indexOf("plot_") != 0) {
                PublicParam.CurrrentModelFileName = title;
            }
            //modelNameLabel.setText(PublicParam.SelectedModelFileName);

            //set current model variable name
            if (PublicParam.ModelName2VariableHashtable.containsKey(PublicParam.CurrrentModelFileName)) {
                PublicParam.CurrentModelVariableName = PublicParam.ModelName2VariableHashtable.get(PublicParam.CurrrentModelFileName).toString();
                this.simulateButton.setEnabled(true);
                this.exploreButton.setEnabled(true);
                this.exportMenuItem.setEnabled(true);
                this.simulateMenuItem.setEnabled(true);
                this.exploreMenuItem.setEnabled(true);
                
            } else {
               PublicParam.CurrentModelVariableName = ""; 
               this.simulateButton.setEnabled(false);
                this.exploreButton.setEnabled(false);
                this.exportMenuItem.setEnabled(false);
                this.simulateMenuItem.setEnabled(false);
                this.exploreMenuItem.setEnabled(false);
            }
            //set navigator selected list
            ListModel lm = navigatorList.getModel();
            for (int i = 0; i < lm.getSize(); i++) {
                String modelName = lm.getElementAt(i).toString();
                if (modelName.equals(PublicParam.CurrrentModelFileName)) {
                    navigatorList.setSelectedIndex(i);
                    break;
                }
            }
        }
    }
    
    //save model to file
    void saveModelContent() {
        try {                  
            //when the text area of model has been changed
            if (!((ModelFile)htModel.get(PublicParam.CurrrentModelFileName)).getIsChanged()) return;
            
            //check directory
            if (navigatorList.getToolTipText() == null || navigatorList.getToolTipText().length() == 0) {
                JOptionPane.showMessageDialog(this, "Please set working directory first!", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            } 
            //check txt file
            if (navigatorList.getSelectedValue() == null || navigatorList.getSelectedValue().toString().length() == 0) {
                JOptionPane.showMessageDialog(this, "Please select model or add model first!", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
            
            //get textarea
            String currentModelName = PublicParam.CurrrentModelFileName; //navigatorList.getSelectedValue().toString();
            JTextArea textarea = ((ModelFile)htModel.get(PublicParam.CurrrentModelFileName)).getEditTextArea();
            
            //String filePath = navigatorList.getToolTipText() + "\\" + navigatorList.getSelectedValue() + ".txt";
            String filePath = ((ModelFile)htModel.get(PublicParam.CurrrentModelFileName)).getFullFilename();
            FileHelper.writeTxtFile(filePath, textarea.getText());
            
            //set textarea which has saved.            
            //textarea.setToolTipText("");
            ((ModelFile)htModel.get(PublicParam.CurrrentModelFileName)).setIsChanged(false);
            modelTabbedPane.setTitleAt(modelTabbedPane.getSelectedIndex(), currentModelName);
            
            //JOptionPane.showMessageDialog(mainPanel, "save model successfully!", "Success", JOptionPane.INFORMATION_MESSAGE);
        } catch (Exception ex) {
            Logger.getLogger(this.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    
    
    
    
    void closeTab(boolean isConfirm) {
        String title = modelTabbedPane.getTitleAt(modelTabbedPane.getSelectedIndex());
        if (title.startsWith("plot_") && !htModel.containsKey(title)) {
            //remove this tab in tabbedpane
            modelTabbedPane.remove(modelTabbedPane.getSelectedIndex());
            return;
        }
        
        //get current model name
        String currentModelName = PublicParam.CurrrentModelFileName;
        
        //get the textarea 
        JTextArea teaxtArea = ((ModelFile)htModel.get(PublicParam.CurrrentModelFileName)).getEditTextArea();
        if (isConfirm && teaxtArea != null && ((ModelFile)htModel.get(PublicParam.CurrrentModelFileName)).getIsChanged()) {
            if (JOptionPane.showConfirmDialog(this, "Current model has changed,do you save this model before closing?", "Question", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                saveModelContent();
            }
        }        
        
        //remove this tab in tabbedpane
        modelTabbedPane.remove(modelTabbedPane.getSelectedIndex());
        
        //remove variable from public params
        htModel.remove(currentModelName);
        if (htModel.size() == 0) PublicParam.CurrrentModelFileName = "";
    }
    
    void deleteModelFile() {
        if (navigatorList.getSelectedValue() == null) {
            //if no seleted model
            JOptionPane.showMessageDialog(this, "Please select a model file from the list of navigator.");            
        } else {
            String modelName = navigatorList.getSelectedValue().toString();
            if (JOptionPane.showConfirmDialog(this, "Are you sure to delete the seleted model" + modelName + "?", "Question", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                if (htModel.containsKey(modelName)) {
                    //this model has been opened.
                    //activate the tab which contains the selected model.
                    this.loadModelFile(false);
                    //remove the tab which contains the selected model.
                    closeTab(false);
                }
                
                //delete the selected model file
                String path = PublicParam.WorkingDirectory + "\\" + modelName + ".txt";
                FileHelper.deleteFile(path);
                
                //remove model form navigate list
                DefaultListModel dlm = (DefaultListModel)navigatorList.getModel();
                dlm.removeElement(modelName);                
            }                        
        }
    }
    
    //save message or error to file
    void saveMessageOrError2File() {
        //show dialog for setting working direcotry
        JFileChooser c = new JFileChooser();
        c.setFileSelectionMode(JFileChooser.SAVE_DIALOG);
        c.setDialogTitle("save message info or error info");
        c.setFileFilter(new TxtFilter());
        
        //set default direcotry
        if (navigatorList.getToolTipText() == null || navigatorList.getToolTipText().length() == 0) {
            //the first of reading the list
            c.setCurrentDirectory(new File(System.getProperty("user.dir")));
        } else {
            //the list has been selected which has been saved in tooltip
            c.setCurrentDirectory(new File(navigatorList.getToolTipText()));
        }
         
        int result = c.showSaveDialog(this);
        if (result == JFileChooser.APPROVE_OPTION) {
            try {
                //working direcotry
                String path = c.getSelectedFile().getAbsolutePath() + ".txt";
                File file = new File(path);
                if(file.exists()){
                    JOptionPane.showConfirmDialog(this, file + "The file already exists, do you overwrite?", "File exists", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
                }
                //save file
                String infoContent = "";
                if (infoTabPanel.getSelectedIndex() == 0) {
                    infoContent = consoleMessageTextArea.getText();
                } else {
                    infoContent = errorTextArea.getText();
                }
                FileHelper.writeTxtFile(path, infoContent);
            } catch (IOException ex) {
                Logger.getLogger(SimHyAMainFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }        
    
    private void changeWorkingDirectory() {
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new java.io.File(((CommandManager)PublicParam.SimHyACommand).getCurrentDirectory()));
        chooser.setDialogTitle("Choose new working directory");
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = chooser.showOpenDialog(this);
        if(returnVal == JFileChooser.APPROVE_OPTION) {
           String newDir; 
           if(chooser.getSelectedFile().isDirectory())
               newDir = chooser.getSelectedFile().getAbsolutePath();
           else 
               newDir = chooser.getSelectedFile().getParent();
           ((CommandManager)PublicParam.SimHyACommand).setCurrentDirectory(newDir);
        }
    }

    private boolean isCommentLine(String command) {
        int i = command.indexOf("//");
        if (i >= 0) {
            for (int j =0; j<i; j++)
                if ( command.charAt(j) != ' ' && command.charAt(j) != '\t' && command.charAt(j) != '\r' )
                    return false;
            return true;
        } else
            return false;
    }

    private boolean isEmptyLine(String command) {
        for (int j =0; j<command.length(); j++)
            if ( command.charAt(j) != ' ' && command.charAt(j) != '\t' && command.charAt(j) != '\r' )
                return false;
        return true;
    }
        
    public void setConsoleTextAreaFocus(String msgType) {
        if (msgType.equals("Info")) {
            //message area
            consoleMessageTextArea.requestFocus();
            consoleMessageTextAreaCaretUpdate(null);
        } else {
            //error message area
            errorTextArea.requestFocus();
            errorTextAreaCaretUpdate(null);
        }
    }
    
    //clear textarea of model    
    private void modelTabbedPaneStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_modelTabbedPaneStateChanged
        setCurrentModelFile();
    }//GEN-LAST:event_modelTabbedPaneStateChanged

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
        this.showAboutBox();
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void simulateMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simulateMenuItemActionPerformed
        simulateButtonActionPerformed(null);
    }//GEN-LAST:event_simulateMenuItemActionPerformed

    private void exploreMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exploreMenuItemActionPerformed
        exploreButtonActionPerformed(null);
    }//GEN-LAST:event_exploreMenuItemActionPerformed

    private void plotMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_plotMenuItemActionPerformed
        plotButtonActionPerformed(null);
    }//GEN-LAST:event_plotMenuItemActionPerformed

    private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItemActionPerformed
        saveButtonActionPerformed(null);
    }//GEN-LAST:event_saveMenuItemActionPerformed

    private void navigatorListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_navigatorListMouseClicked
        if (evt.getClickCount() == 2) {
            //when double click JList
            this.loadModelFile(false);
        }            
    }//GEN-LAST:event_navigatorListMouseClicked

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        // TODO add your handling code here:        
    }//GEN-LAST:event_formComponentShown
        
    private void closeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeMenuItemActionPerformed
        closeTab(true);
    }//GEN-LAST:event_closeMenuItemActionPerformed

    private void modelTabbedPaneMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_modelTabbedPaneMouseClicked
        if (evt.getClickCount() == 2) {
            //double click
            closeTab(true);
        }
    }//GEN-LAST:event_modelTabbedPaneMouseClicked

    //clear message or error
    private void clearMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearMenuItemActionPerformed
        if (infoTabPanel.getSelectedIndex() == 0) {
            //message
            consoleMessageTextArea.setText("");
        } else {
            //error message
            errorTextArea.setText("");
        }
    }//GEN-LAST:event_clearMenuItemActionPerformed

    private void closealltabsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closealltabsMenuItemActionPerformed
        for (int i = modelTabbedPane.getTabCount() - 1; i >= 0; i--) {
            //set current tab
            modelTabbedPane.setSelectedIndex(i);
            //close current tab
            closeTab(true);
        }
    }//GEN-LAST:event_closealltabsMenuItemActionPerformed

    private void closeothertabsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeothertabsMenuItemActionPerformed
        int selectedIndex = modelTabbedPane.getSelectedIndex();
        //close tab from selectedIndex+1 to tabCount
        for (int i = modelTabbedPane.getTabCount() - 1; i > selectedIndex; i--) {
            //set current tab
            modelTabbedPane.setSelectedIndex(i);
            //close current tab
            closeTab(true);
        }
        //close tab from 0 to selectedIndex-1
        for (int i = selectedIndex - 1; i >= 0; i--) {
            //set current tab
            modelTabbedPane.setSelectedIndex(i);
            //close current tab
            closeTab(true);
        }
    }//GEN-LAST:event_closeothertabsMenuItemActionPerformed

    //save message or error to file
    private void saveasMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveasMenuItemActionPerformed
        saveMessageOrError2File();
    }//GEN-LAST:event_saveasMenuItemActionPerformed

    private void commandTextKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_commandTextKeyReleased
        //System.out.println("size:" + PublicParam.history.size());
        //System.out.println("pos:" + PublicParam.historyPos);
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            String command = commandText.getText();
            if (command.length() > 0) {
                
                
                if (command.equals("quit") || command.equals("exit")) {
                    PublicParam.history.add(command);
                    PublicParam.historyPos = PublicParam.history.size() - 1;
                    consoleMessageTextArea.setText("");
                    int n = JOptionPane.showConfirmDialog(this, "Exit SimHyA. Are you sure?");
                    if (n== JOptionPane.YES_OPTION)
                        System.exit(0);
                    else {
                        consoleMessageTextArea.setText("\n > " + command);
                        consoleMessageTextArea.setText("Quit from SymHyA canceled by user.");    
                    }
                } else if (command.equals("clear")) {
                    PublicParam.history.add(command);
                    PublicParam.historyPos = PublicParam.history.size() - 1;
                    commandText.setText("");
                    consoleMessageTextArea.setText("SimHyA simulator version " + simhya.GlobalOptions.version);
                } else if (command.equals("gwd")) {
                    PublicParam.history.add(command);
                    PublicParam.historyPos = PublicParam.history.size() - 1;
                    commandText.setText("");
                    consoleMessageTextArea.setText("\n > " + command);
                    consoleMessageTextArea.setText("Current working directory is " + ((CommandManager)PublicParam.SimHyACommand).getCurrentDirectory());
                } else if (command.equals("cwd")) {
                    PublicParam.history.add(command);
                    PublicParam.historyPos = PublicParam.history.size() - 1;
                    commandText.setText("");
                    this.changeWorkingDirectory();
                    consoleMessageTextArea.setText("\n > " + command);
                    consoleMessageTextArea.setText("Current working directory is " + ((CommandManager)PublicParam.SimHyACommand).getCurrentDirectory());
                } else if (isEmptyLine(command) || isCommentLine(command)) {

                } else if(!command.isEmpty()) {
                    //System.out.println(command);
                    //PublicParam.SimHyACommand.execute(s);
                    PublicParam.SimHyACommandExpression = command;
                    SimHyAHelper.executeCommand();
                    commandText.setText("");
                    //set messages visible automatically
                    consoleMessageTextArea.setCaretPosition(consoleMessageTextArea.getDocument().getLength());
                    errorTextArea.setCaretPosition(errorTextArea.getDocument().getLength());
                }
            }
            commandText.requestFocus();
        } else if (evt.getKeyCode() == KeyEvent.VK_UP) {
            //System.out.println(PublicParam.history.size());
            //System.out.println(PublicParam.history.get(PublicParam.historyPos));
            if (PublicParam.historyPos >= 0) {
                commandText.setText(PublicParam.history.get(PublicParam.historyPos--));
            }
        } else if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            if (PublicParam.historyPos < PublicParam.history.size()-1) {
                commandText.setText(PublicParam.history.get(++PublicParam.historyPos));
            } else if (PublicParam.historyPos == PublicParam.history.size()-1) {
                commandText.setText("");
            }
        }
    }//GEN-LAST:event_commandTextKeyReleased
    
    private void saveModelMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveModelMenuItemActionPerformed
        saveModelContent();
    }//GEN-LAST:event_saveModelMenuItemActionPerformed

    private void deleteModelMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteModelMenuItemActionPerformed
        deleteModelFile();
    }//GEN-LAST:event_deleteModelMenuItemActionPerformed

    private void newMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newMenuItemActionPerformed
        //show the form of adding model
        if (showAddModelForm()) {
            //load empty model file
            this.loadModelFile(false);
        }
    }//GEN-LAST:event_newMenuItemActionPerformed

    private void errorTextAreaCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_errorTextAreaCaretUpdate
        //visualize error message 
        infoTabPanel.setSelectedIndex(1);
        //set messages visible automatically
        if (errorMessageLength != errorTextArea.getText().length()) {
            errorMessageLength = errorTextArea.getText().length();
            errorTextArea.setCaretPosition(errorTextArea.getDocument().getLength());
        }
    }//GEN-LAST:event_errorTextAreaCaretUpdate

    private void parseMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_parseMenuItemActionPerformed
        loadModelFile(true);
    }//GEN-LAST:event_parseMenuItemActionPerformed

    private void consoleMessageTextAreaCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_consoleMessageTextAreaCaretUpdate
        //set messages visible automatically
        if (consoleMessageLength != consoleMessageTextArea.getText().length()) {
            consoleMessageLength = consoleMessageTextArea.getText().length();
            consoleMessageTextArea.setCaretPosition(consoleMessageTextArea.getDocument().getLength());
        }
    }//GEN-LAST:event_consoleMessageTextAreaCaretUpdate

    private void closetabPopupMenuPopupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_closetabPopupMenuPopupMenuWillBecomeVisible
        //enable menu items of tab
        if (modelTabbedPane.getSelectedIndex() >= 0) {
            String title = modelTabbedPane.getTitleAt(modelTabbedPane.getSelectedIndex());
            if (title.indexOf("plot_") == 0) {
                detachfromtabMenuItem.setEnabled(true);
            } else {
                detachfromtabMenuItem.setEnabled(false);
            }
        }
    }//GEN-LAST:event_closetabPopupMenuPopupMenuWillBecomeVisible

    private void detachfromtabMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_detachfromtabMenuItemActionPerformed
        //active plot chart in a new window
        JFrame f = new JFrame();        
        f.setSize(800, 600);
                
        //show the window in center
        double width = Toolkit.getDefaultToolkit().getScreenSize().getWidth(); 
        double height = Toolkit.getDefaultToolkit().getScreenSize().getHeight(); 
        f.setLocation((int)(width - f.getWidth()) / 2, (int)(height - f.getHeight()) / 2); 
        
        f.add(modelTabbedPane.getSelectedComponent());
        f.setVisible(true);
    }//GEN-LAST:event_detachfromtabMenuItemActionPerformed

    private void showorhideMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showorhideMenuItemActionPerformed
        //System.out.println(evt.toString());
        if (evt.getActionCommand().endsWith("Hide Console")) {
            showorhideMenuItem.setText("Show Console");
            infoTabPanel.setVisible(false);
        } else {
            showorhideMenuItem.setText("Hide Console");
            infoTabPanel.setVisible(true);
        }
    }//GEN-LAST:event_showorhideMenuItemActionPerformed
    
    
    private void openNavigatorMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openNavigatorMenuItemActionPerformed
        this.loadModelFile(false);
    }//GEN-LAST:event_openNavigatorMenuItemActionPerformed

    private void parseNavigatorMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_parseNavigatorMenuItemActionPerformed
        loadModelFile(true);
    }//GEN-LAST:event_parseNavigatorMenuItemActionPerformed

    private void deleteNavigatorMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteNavigatorMenuItemActionPerformed
        deleteModelFile();
    }//GEN-LAST:event_deleteNavigatorMenuItemActionPerformed

    private void helpMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpMenuItemActionPerformed
       WinHelper.showHelp("index");
    }//GEN-LAST:event_helpMenuItemActionPerformed

    private void closethistabMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closethistabMenuItemActionPerformed
        closeTab(true);
    }//GEN-LAST:event_closethistabMenuItemActionPerformed

private void exportMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportMenuItemActionPerformed
    if (PublicParam.CurrentModelVariableName.isEmpty())
        JOptionPane.showMessageDialog(this, "Please parse a model first.", "Error: model not parsed", JOptionPane.ERROR_MESSAGE);
    else
        WinHelper.showDialog(PublicParam.ExportModelForm,ExportModelForm.class);
}//GEN-LAST:event_exportMenuItemActionPerformed

private void loadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadButtonActionPerformed
        loadModelFile(true);
}//GEN-LAST:event_loadButtonActionPerformed

private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
        showFileDialog();
}//GEN-LAST:event_browseButtonActionPerformed

private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        PublicParam.CommandTypeName = "save";
        WinHelper.showDialog(PublicParam.SimulateSaveForm, SimulateSaveForm.class);
}//GEN-LAST:event_saveButtonActionPerformed

private void plotButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_plotButtonActionPerformed
        PublicParam.CommandTypeName = "plot";
        //active the new model form
        WinHelper.showDialog(PublicParam.PlotForm, PlotForm.class);
}//GEN-LAST:event_plotButtonActionPerformed

private void exploreButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exploreButtonActionPerformed
        if (this.checkLoadModel()) {
            PublicParam.CommandTypeName = "explore";
            //close simulate( and explore) form,because simulate use the same form as explose
            WinHelper.closeFormAfterCommand();
            if (!PublicParam.CurrentModelVariableName.equals(PublicParam.LastSimulatedModelVariableName))
                WinHelper.closeAdvancedFormAfterCommand();
            PublicParam.LastSimulatedModelVariableName = PublicParam.CurrentModelVariableName;
            //show new model form
            WinHelper.showDialog(PublicParam.SimulateForm, SimulateForm.class);
            this.plotButton.setEnabled(true);
            this.saveButton.setEnabled(true);
            this.saveMenuItem.setEnabled(true);
            this.plotMenuItem.setEnabled(true);
        }
}//GEN-LAST:event_exploreButtonActionPerformed

private void simulateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simulateButtonActionPerformed
        if (this.checkLoadModel()) {
            PublicParam.CommandTypeName = "simulate";
            //close simulate or explore) form, because simulate and explore use the same form
            WinHelper.closeFormAfterCommand();
            if (!PublicParam.CurrentModelVariableName.equals(PublicParam.LastSimulatedModelVariableName))
                WinHelper.closeAdvancedFormAfterCommand();
            PublicParam.LastSimulatedModelVariableName = PublicParam.CurrentModelVariableName;
            //show new model form
            WinHelper.showDialog(PublicParam.SimulateForm, SimulateForm.class);
            this.plotButton.setEnabled(true);
            this.saveButton.setEnabled(true);
            this.saveMenuItem.setEnabled(true);
            this.plotMenuItem.setEnabled(true);
        }
}//GEN-LAST:event_simulateButtonActionPerformed

private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
    int n = JOptionPane.showConfirmDialog(this, "Exit SimHyA. Are you sure?");
        if (n== JOptionPane.YES_OPTION) {
           System.exit(0);
        }
}//GEN-LAST:event_exitMenuItemActionPerformed

private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
    readModelNameToList(PublicParam.WorkingDirectory);
}//GEN-LAST:event_refreshButtonActionPerformed
            
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SimHyAMainFrame().setVisible(true);
            }
        });
    }
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton browseButton;
    private javax.swing.JMenuItem clearMenuItem;
    private javax.swing.JPopupMenu clearPopupMenu;
    private javax.swing.JMenuItem closeMenuItem;
    private javax.swing.JMenuItem closealltabsMenuItem;
    private javax.swing.JMenuItem closeothertabsMenuItem;
    private javax.swing.JPopupMenu closetabPopupMenu;
    private javax.swing.JMenuItem closethistabMenuItem;
    private javax.swing.JTextField commandText;
    private javax.swing.JTextArea consoleMessageTextArea;
    private javax.swing.JTextField currentDirField;
    private javax.swing.JMenuItem deleteModelMenuItem;
    private javax.swing.JMenuItem deleteNavigatorMenuItem;
    private javax.swing.JMenuItem detachfromtabMenuItem;
    private javax.swing.JTextArea errorTextArea;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JButton exploreButton;
    private javax.swing.JMenuItem exploreMenuItem;
    private javax.swing.JMenuItem exportMenuItem;
    private javax.swing.JMenuItem helpMenuItem;
    private javax.swing.JTabbedPane infoTabPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator10;
    private javax.swing.JSeparator jSeparator11;
    private javax.swing.JSeparator jSeparator12;
    private javax.swing.JPopupMenu.Separator jSeparator13;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JPopupMenu.Separator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JSeparator jSeparator8;
    private javax.swing.JSeparator jSeparator9;
    private javax.swing.JTextArea jTextArea3;
    private javax.swing.JButton loadButton;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JTabbedPane modelTabbedPane;
    private javax.swing.JList navigatorList;
    private javax.swing.JPopupMenu navigatorPopupMenu;
    private javax.swing.JMenuItem newMenuItem;
    private javax.swing.JMenuItem openNavigatorMenuItem;
    private javax.swing.JMenuItem parseMenuItem;
    private javax.swing.JMenuItem parseNavigatorMenuItem;
    private javax.swing.JButton plotButton;
    private javax.swing.JMenuItem plotMenuItem;
    private javax.swing.JButton refreshButton;
    private javax.swing.JButton saveButton;
    private javax.swing.JMenuItem saveMenuItem;
    private javax.swing.JMenuItem saveModelMenuItem;
    private javax.swing.JMenuItem saveasMenuItem;
    private javax.swing.JMenuItem saveasModelMenuItem;
    private javax.swing.JMenuItem showorhideMenuItem;
    private javax.swing.JButton simulateButton;
    private javax.swing.JMenuItem simulateMenuItem;
    // End of variables declaration//GEN-END:variables
    
    private JDialog aboutBox;
    private javax.swing.JDialog newModelForm;
    private Hashtable htModel = new Hashtable();
    private String softTitle = "";
    private int consoleMessageLength = 0, errorMessageLength = 0;
 
}


